<template>
    <div style="height: 100%" class="warp-2 body-content">
        <navbar :title="$t('mall_4')"></navbar>
        <div class="content-noBottom">
            <van-pull-refresh v-model="isRefresh" @refresh="onPulldownTop" loading-text="loading" pulling-text="" loosing-text="" style="height: 100%;">
                <van-list
                v-model="isLoading"
                :finished="finished"
                :finished-text="(finished&&total>0) ? $t('no_more') : ''"
                loding-text="loading"
                @load="getMallList"
                >
                    <div class="mall-body">
                        <div class="mall-list">
                            <div :class="index < 3 ? 'mall-item-2' : 'mall-item'" v-for="(item, index) in list" :key="item.impId">
                                <div class="mall-style" :class="{'mall-style-border' : index >= 3}">
                                    <div class="item-num">
                                        <div :class="index | numClassHandle">{{index | numHandle}}</div>
                                    </div>
                                    <div class="item-info">
                                        <div class="item-title">{{ item.impName }}</div>
                                        <div class="item-type"><span>{{ $t('mall_5') }}</span>：<span>{{ item.imCatalogStr }}</span></div>
                                        <div class="item-more">
                                            <div>
                                                <i class="iconfont icon-jifen" style="font-size: 14px;color: #9F9F9F"></i>
                                                <span>{{ $t('mall_17', {'value': item.impExchange}) }}</span>
                                            </div>
                                            <div>
                                                <span>{{ $t('mall_18') }} </span><span>({{ item.impExchangeTotal}})</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div v-if="list.length === 0" style="height: calc(100vh - 76px)">
                            <div class="box-table" style="width:100%;height:100%;">
                                <div class="box-table-cell" style="text-align: center;">
                                    <div class="no-data">
                                        <img src="../../../static/images/no-data.png" alt=""/>
                                        <p class="color999">{{ $t("no_data") }}</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </van-list>
            </van-pull-refresh>
        </div>
        <common-loading :isLoading="isLoading"></common-loading>
    </div>
</template>

<script>
export default {
    name: 'MallTopList',
    data() {
        return {
            total: 0,
            pageNo: 0,
            list: [],
            isLoading: false,
            finished: false,
            isRefresh: false
        };
    },
    filters: {
        numHandle(value) {
            let v = value + 1;
            if (v.toString().length === 1) {
                return '0' + v;
            }
            return v;
        },
        numClassHandle(value) {
            switch (value) {
            case 0 :
                return 'num-top num-01';
            case 1:
                return 'num-top num-02';
            case 2:
                return 'num-top num-03';
            default:
                return 'num-n';
            }
        }
    },
    methods: {
        getMallList(option) {
            this.$axios.post(`/app/api/trainee/im/product/list?pageNo=${this.pageNo}`, {imcId: 0, type: 2}).then(res => {
                if (res.data.results && res.data.results.length !== 0) {
                    if (option && option === 'refresh') {
                        this.list = res.data.results;
                    } else {
                        this.list = [...this.list, ...res.data.results];
                    }
                }
                this.total = res.data.totalRecord;
                this.isLoading = false;
                this.pageNo++;
                if (this.list.length >= this.total) {
                    this.finished = true;
                }
            });
        },
        /*下拉刷新*/
        onPulldownTop() {
            this.isRefresh = true;
            setTimeout(() => {
                this.finished = false;
                this.pageNo = 1;
                this.getMallList('refresh');
                this.isRefresh = false;
            }, 900);
        }
    },
    created() {
        this.onPulldownTop();
    }
};
</script>

<style scoped lang="less">
    .mall-body {
        .mall-list {
            padding: 10px 15px;
            .mall-item {
                background: #fff;
                padding: 0 10px;
                &:nth-child(4) {
                    border-top-left-radius: 5px;
                    border-top-right-radius: 5px;
                }
                &:last-child {
                    border-bottom-left-radius: 5px;
                    border-bottom-right-radius: 5px;
                }
            }
            .mall-item-2 {
                background: #fff;
                padding: 0 10px;
                margin-bottom: 10px;
                border-radius: 5px;
            }
            .mall-style-border {
                border-bottom: 1px solid #F8F8F8;
            }
            .mall-style {
                display: flex;
                align-items: center;
                justify-content: space-between;
                padding: 10px 0;
                .item-num {
                    width: 70px;
                    height: 60px;
                    &>div {
                        width: 60px;
                        height: 60px;
                        text-align: center;
                        color: #666666;
                        border-radius: 2px;
                        font-size: 18px;
                    }
                    .num-top {
                        font-size: 24px;
                        color: #fff;
                        font-family: alibaba-font;
                        font-style:oblique;
                        line-height: 60px;
                    }
                    .num-01 {
                        background: #075ebb;
                    }
                    .num-02 {
                        background: #3491EF;
                    }
                    .num-03 {
                        background: #5AA4EE;
                    }
                }
                .item-info {
                    flex: 1;
                    height: 60px;
                    display: flex;
                    flex-direction: column;
                    justify-content: space-between;
                    min-width: 0;
                    .item-title {
                        overflow: hidden;
                        text-overflow: ellipsis;
                        white-space: nowrap;
                    }
                    .item-type {
                        font-size: 10px;
                        &>span:first-child {
                            color: #9F9F9F;
                        }
                        &>span:last-child {
                            color: #797979;
                        }
                    }
                    .item-more {
                        display: flex;
                        align-items: center;
                        justify-content: space-between;
                        font-size: 10px;
                        &>div:first-child>span {
                            color: #797979;
                        }
                        &>div:last-child {
                            &>span:first-child {
                                color: #9F9F9F;
                            }
                            &>span:last-child {
                                color: #797979;
                            }
                        }
                    }
                }
            }
        }
    }
</style>
